<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/jsp/struts/taglibs.jsp" %>
<head>
<script type="text/javascript"  src="script/prototype.js"></script>
<script type="text/javascript"  src="script/common.js"></script>
<link href="./style/alternative.css" media="all" rel="stylesheet" />
<style type="text/css">
#taskList {
	border: 2px broove #eee;
	margin-top: 1em;
	line-height:1.8em;
	width:95%
}
#taskList th{
    text-align:center
}
#taskListt td{
    border: 1px solid #eee;
}
.taskOperation td a {
    white-space: nowrap;
}

#taskFilter {
	font-size: 0.8em;
	padding-left: 0.1em;
	padding-right: 1.5em;
	white-space:nowrap;
	vertical-align:middle;
	text-align:center;
}
</style>
<SCRIPT LANGUAGE="JavaScript">
function doAction(imethod, taskID) {
    if(imethod == 'delete') {
        var ret = confirm("你确信删除这项任务吗?");
        if(ret) {
        	location.href = "task.htm?method=delete&taskID=" + taskID;
        }
    } else {
    	location.href = "task.htm?method=" + imethod + "&taskID=" + taskID;
    }
}
</SCRIPT>
</head>
<body>
<div id="content">
<div id="content_inner">
<center>
<h2>
<c:choose>
<c:when test="${param.taskType==1}">
下一步行动
</c:when>
<c:when test="${param.taskType==2}">
日程表
</c:when>
<c:when test="${param.taskType==3}">
等待任务清单
</c:when>
<c:when test="${param.taskType==4}">
已完成任务
</c:when>

<c:otherwise>
<a href="task.htm">任务列表</a>
</c:otherwise>
</c:choose>
</h2>
</center>

<br/>
<div id="taskFilter">
<form id="taskForm" name="taskForm" method="get" action="task.htm">
环境: <select name="contextID" id="contextID">
<option value="0">-请选择-</option>
<c:forEach items="${contexts}" var="entry">
    <OPTION VALUE="${entry.key}">${entry.value.description}
</c:forEach>
</select>
&nbsp;
时间&lt; <input type="text" id="duration" name="duration" size="2">
<label>分钟</label>&nbsp;
重要性: <select id="priority" name="priority">
<option value="0">-请选择-</option>
<option value="1">重要且紧急</option>
<option value="2">重要不紧急</option>
<option value="3">紧急不重要</option>
<option value="4">不重要不紧急</option>
</select>&nbsp;
精力: <select id="energy">
<option value="0">-请选择-</option>
<option value="90">充沛</option>
<option value="60">一般</option>
<option value="30">疲倦</option>
</select>
任务: <input type="text" id="taskName" name="taskName" size="10">
<input type="hidden" name="method" id="method" value="find">
<input type="submit" id="btnFind" value="过滤">
</form>
</div>
<c:set var="now" value="<%=new java.util.Date()%>" />
<display:table htmlId="taskList" name="taskList" sort="list"  
    class="its" id="task" requestURI="task.htm">
<display:setProperty name="basic.empty.showtable" value="true" />
<display:setProperty name="basic.msg.empty_list_row" value="<tr class='empty'><td colspan='{0}'>没有记录</td></tr>"/>
<display:column title="&nbsp;&nbsp;&nbsp;任务" sortable="true" headerClass="sortable">
<INPUT TYPE="hidden" NAME="${task.taskID}" ID="${task.taskID}">
<img src="images/bullet.gif"/>&nbsp;
<a href="task.htm?method=retrieve&taskID=${task.taskID}" title="${task.description}">${task.taskName}</a>
<c:if test="${task.repeatID > 0}">
<span style="color:blue">(循环)</span>
</c:if>
</display:column>
<display:column title="优先级" sortable="true" headerClass="sortable">
${task.priority}.
<c:choose>
	<c:when test="${task.priority==1}">
	重要且紧急
	</c:when>
	<c:when test="${task.priority==2}">
	重要不紧急
	</c:when>
	<c:when test="${task.priority==3}">
	紧急不重要
	</c:when>
	<c:when test="${task.priority==4}">
	不重要不紧急
	</c:when>
	<c:otherwise>
	未定义
	</c:otherwise>
</c:choose>
</display:column>
<display:column title="开始时间" sortable="true" headerClass="sortable" style="width:3em">
<span>
<fmt:formatDate value="${task.beginTime}" pattern="MM/dd/yy HH:mm:ss"/>
</span>
</display:column>
<display:column title="截止时间" sortable="true" headerClass="sortable" style="width:3em">
<c:if test="${task.repeatID == 0}">
<span 
<c:if test="${task.deadline < now}">
style="color: red"
</c:if>
>
<fmt:formatDate value="${task.deadline}" pattern="MM/dd/yy HH:mm:ss"/>
</span>
</c:if>
<c:if test="${task.repeatID > 0}">
<span id="repeatInfo_${task.repeatID}"> <span>
<script language="javascript">
var onRepeatInfoFound = function(data) {
    var exDate = data.expireTime;
    if(exDate) {
        document.getElementById("repeatInfo_${task.repeatID}").innerHTML = exDate.pattern("yyyy-MM-dd hh:mm:ss");
    }
}
DWRService.getRepeatInfo(${task.repeatID}, onRepeatInfoFound);
</script>
</c:if>
</display:column>
<display:column title="预计时间" sortable="true" headerClass="sortable">
<c:choose>
<c:when test="${task.duration >= 1440}">
<fmt:formatNumber value="${task.duration/1440}" type="number" maxFractionDigits="2"/> 天
</c:when>
<c:when test="${task.duration >= 60}">
<fmt:formatNumber value="${task.duration/60}" type="number" maxFractionDigits="2"/> 小时
</c:when>
<c:otherwise>
${task.duration} 分钟
</c:otherwise>
</c:choose>

</display:column>

<display:column title="<input type=\"button\" onclick=\"location.href='task.htm?method=add'\" value=\"添加任务\"/>" class="taskOperation">
<a href="#" onclick="doAction('finish',${task.taskID})" class="icon_btn pic_right" title="Finish Task"><span>Finish Task</span></a>
<a href="#" onclick="doAction('edit',${task.taskID})"  class="icon_btn pic_edit" title="Edit Task"><span>Edit Task</span></a>
<a href="#" onclick="doAction('delete',${task.taskID})" class="icon_btn pic_delete" title="Delete Task"><span>Delete Task</span></a>
</display:column> 
</display:table>

</div><!-- end content_inner -->
</div><!-- end content -->

<script language="Javascript">
<c:if test="${not empty foundTask}">
var defaultContextID = "" + "${foundTask.contextID}";
toSelect("contextID",defaultContextID);

var defaultEnergy = "" + "${foundTask.energy}";
toSelect("energy",defaultEnergy);

var defaultPriority = "" + "${foundTask.priority}";
toSelect("priority",defaultPriority);

var defaultName = "" + "${foundTask.taskName}";
$('taskName').value = defaultName;

</c:if>
</script>
